package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.CoverDto;
import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.dto.DTResponseDto;
import com.hualude.roadsign.dto.JsonMsgDto;
import com.hualude.roadsign.service.CoverManageService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/rds_CoverManage")
public class CoverManageController {
    @Resource
    private CoverManageService coverService;

    @RequestMapping("/getCover4DT")
    @ResponseBody
    public DTResponseDto getCover4DT(DTRequestDto dtRequestDto,
                                     String actorIds,
                                     Integer orgId,
                                     Boolean audit,
                                     String startRoad,
                                     String endRoad,
                                     String roadName) throws Exception {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = coverService.getCover4DT(
                    dtRequestDto, actorIds, orgId, audit, startRoad, endRoad, roadName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/deleteCover")
    @ResponseBody
    public JsonMsgDto deleteCover(String coverIds) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(coverService.deleteCover(coverIds));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/addCover")
    @ResponseBody
    public JsonMsgDto addCover(CoverDto coverDto) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(coverService.addCover(coverDto));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/updateCover")
    @ResponseBody
    public JsonMsgDto updateCover(CoverDto coverDto) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(coverService.updateCover(coverDto));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getStartRoadByRoadName")
    @ResponseBody
    public JsonMsgDto getStartRoadByRoadName(String roadName, String actorIds, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(coverService.getStartRoadByRoadName(roadName, actorIds, orgId));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getEndRoadByStartRoad")
    @ResponseBody
    public JsonMsgDto getEndRoadByStartRoad(String city, String coverRoadName, String startRoad, String actorIds, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(coverService.getEndRoadByStartRoad(city, coverRoadName, startRoad, actorIds, orgId));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getCover4APP")
    @ResponseBody
    public JsonMsgDto getCover4APP(String actorIds,
                                   Integer orgId,
                                   Integer mCount,
                                   Integer mSize,
                                   String city,
                                   String startRoad,
                                   String endRoad,
                                   String roadName) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(coverService.getCover4APP(
                    actorIds, orgId, mCount, mSize, city, startRoad, endRoad, roadName));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getCoverById")
    @ResponseBody
    public JsonMsgDto getCoverById(Integer coverId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(coverService.getCoverById(coverId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getCity4Cover4App")
    @ResponseBody
    public JsonMsgDto getCity4Cover4App(String actorIds, Integer orgId, Integer mCount, Integer mSize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(coverService.getCity4Cover4App(actorIds, orgId, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getRoadName4CoverByCity")
    @ResponseBody
    public JsonMsgDto getRoadName4CoverByCity(String actorIds, Integer orgId, String city, Integer mCount, Integer mSize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(coverService.getRoadName4CoverByCity(actorIds, orgId, city, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getStartRoadByRoadName4App")
    @ResponseBody
    public JsonMsgDto getStartRoadByRoadName4App(String city, String roadName, String actorIds, Integer orgId, Integer mCount, Integer mSize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(coverService.getStartRoadByRoadName4App(city, roadName, actorIds, orgId, mCount, mSize));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getEndRoadByStartRoad4App")
    @ResponseBody
    public JsonMsgDto getEndRoadByStartRoad4App(String city, String coverRoadName, String startRoad, String actorIds, Integer orgId, Integer mCount, Integer mSize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(coverService.getEndRoadByStartRoad4App(city, coverRoadName, startRoad, actorIds, orgId, mCount, mSize));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getCover4Map4App")
    @ResponseBody
    public JsonMsgDto getCover4Map4App(Integer orgId,
                                       String actorIds,
                                       double neLongitude,
                                       double neLatitude,
                                       double swLongitude,
                                       double swLatitude) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(coverService.getCover4Map4App
                    (orgId, actorIds, neLongitude, neLatitude, swLongitude, swLatitude));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/auditCover")
    @ResponseBody
    public JsonMsgDto auditCover(String coverIds) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(coverService.auditCover(coverIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }
}
